# application/mapper/system/dict.py
from application.extensions.databases import db
from application.models.system.dict_type import SysDictType
from application.models.system.dict_data import SysDictData
from typing import List, Dict, Any


class DictTypeMapper:
    """字典数据访问层"""

 
    @staticmethod
    def get_all_dict_types() -> List[SysDictType]:
        """
        获取所有字典类型
        :return: 字典类型列表
        """
        return db.session.query(SysDictType).order_by(SysDictType.create_time.desc()).all()

    @staticmethod
    def create_dict_type(dict_type:SysDictType) -> List[SysDictType]:
        """
        创建字典类型
        :param dict_type: 字典类型对象
        :return: 创建后的字典类型对象
        """
        db.session.add(dict_type)
        db.session.commit()
        return dict_type
    
    
    @staticmethod
    def update_dict_data(dict_type: SysDictType) -> SysDictType:
        """
        更新产品型号
        :param product_model: 产品型号对象
        :return: 更新后的产品型号对象
        """
        db.session.commit()
        return dict_type
    @staticmethod
    def get_dict_Type_by_id(dict_id: int) -> SysDictType:
        """
        根据ID获取字典数据
        :param dict_id: 字典数据ID
        :return: 字典数据对象
        """
        return (
            db.session.query(SysDictType)
            .filter(SysDictType.dict_id == dict_id)
            .first()
        )